/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package martino;

/**
 *
 * @author sempere
 */
public class PortVector {
    
    //by default, with the UNO analog and digital inputs.
    public int[] analogVector;
    public int[] digitalVector;
    
    public int numAnalogs = 6;
    public int numDigitals = 14;
    
    public int RX= 0, TX = 1;
    
    
    public PortVector(){
       
    }
    
    public void init(){
        
        analogVector = new int[numAnalogs];
        digitalVector = new int[numDigitals];
        
        for(int i= 0; i< numAnalogs; i++){
            analogVector[i] = 0;
        }
        
        for(int i= 0; i< numDigitals; i++){
            digitalVector[i] = 0;
        }
        
        digitalVector[RX] = -2;
        digitalVector[TX] = -1;
        
    }
    
    public boolean on(String port){
        
        int numport;
        if(port.charAt(0)=='A' || port.charAt(0)=='a'){
            port = port.substring(1);
            numport = Integer.parseInt(port);
            if (numport < numAnalogs){
                analogVector[numport] = 1;
            } else {
                return false;
            }
        } else {
            numport = Integer.parseInt(port);
            if(numport<numDigitals && numport!=RX && numport!=TX){
                digitalVector[numport] = 1;
            } else {
                return false;
            }
        }
        return true;
    }
    
    
    
     public boolean isOnDigital(int port){
        return (digitalVector[port] == 1);
       
    }
     
     public boolean isOnAnalog(int port){
        return (analogVector[port] == 1);
       
    }
    
}
